package cn.com.haopy.yue.ai.db.service;

import cn.com.haopy.yue.ai.db.entity.BaseEntity;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @author keel
 * @date 2022/4/24
 */
public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> extends ServiceImpl<M, T> implements IBaseService<T> {
    public boolean updateByIdWithOptimisticLock(T t) {
        LambdaQueryWrapper<T> queryWrapper = new LambdaQueryWrapper<>((Class<T>) t.getClass());
        queryWrapper.eq(T::getId, t.getId()).eq(T::getUpdateTime, t.getUpdateTime());

        return super.update(t, queryWrapper);
    }
}
